package sxe.core.cs511.team2_2;
import java.util.Vector;

/**OVERVIEW: This is a container class for Blobs. It is used to store all the Blob objects corresponding to a Frame 
 * The abstraction function is AF(c) = {The elements in a vector of Blob objects}
 * The repinvariant is that the blob objects blobVector contains the blobs in a frame.
 * 
 * @author wajeeha
 *
 */
public class BlobBag {
	/**
	 * This is a vector of blobs, used for storing a blob collection 
	 */ 
	private Vector<Blob> blobVector= new Vector<Blob>();

	/**
	 * The timestamp of creation of the blobbag
	 */ 	
	private java.util.Date stamp;

	/**
	 * Constructs new bag with given time stamp
	 */
	public BlobBag(java.util.Date date){
		stamp=date;
	}
	/**
	 * Constructs new bag with time stamp of current time
	 */
	public BlobBag(){
		stamp=java.util.Calendar.getInstance().getTime();
	}
	/**
	 * EFFECTS: returns timestamp of bag
	 */
	public java.util.Date getStamp(){
		return stamp;
	}
	/** EFFECTS:  returns the number of blobs in this blobbag
	 * 
	 */
	public int size(){
		return blobVector.size();
	}
	/**
	 * EFFECTS: returns unmodifiable list iterator for blobs in bag
	 */
	public java.util.Iterator<Blob> listIterator(){
		return blobVector.iterator();//java.util.Collections.unmodifiableList(blobVector).listIterator();
	}
	/**
	 * MODIFIES: this
	 * EFFECTS: if b is not null, it is added to bag
	 */
	public void add(Blob b){
		if(b==null) return;
		blobVector.addElement(b);
	}
	/** EFFECTS:  returns the blob at the specified index in the blob vector
	 * 
	*/
	public Blob getBlob(int index)
	{
		return blobVector.get(index);
	}
	/** EFFECTS:  Deletes the blob passed as an argument from the blobbag (if found)
	 *  MODIFIES: blobVector
	 * 
	*/
	public boolean deleteBlob(Blob b){
		return blobVector.remove(b);
	}
	/** EFFECTS:  remove the blob at the specified index in the blob vector, returns true if removed,false if not 
	 *  MODIFIES: blobVector
	 * 
	*/
	public boolean deleteBlob(int index){
		Blob b = blobVector.remove(index);
		if(b == null)
			return false;
		else
			return true;
	
	}
}
